home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / cubic_t.cpp < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  114 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  CUBIC_T.CPP - Cubic Tetrahedron Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #include "cubic_t.h"
  39.  
  40. void CubicTetra::CalcFormFactors( Patch3 *pp, Instance
  41.     *pi, float *ff_array, WORD num_elem )
  42. {
  43.   int i;                // Loop index
  44.   BOOL hidden;          // Patch visibility flag
  45.   BOOL self;            // Self patch flag
  46.   WORD j;               // Loop index
  47.   WORD elem_id;         // Element identifier
  48.   Element3 *pelem;      // Element pointer
  49.   Instance *pinst;      // Instance pointer
  50.   Patch3 *ppatch;       // Patch pointer
  51.   Surface3 *psurf;      // Surface pointer
  52.  
  53.   // Clear the form factors array
  54.   for (j = 0; j < num_elem; j++)
  55.     ff_array[j] = (float)0.0;
  56.  
  57.   // Set the cubic tetrahedron view transformation matrix
  58.   clip.SetView(pp);
  59.  
  60.   // Project environment onto each cubic tetrahedron face
  61.   for (i = 0; i < CubicFaceNum; i++)
  62.   {
  63.     // Update view transformation matrix
  64.     clip.UpdateView(i);
  65.  
  66.     scan.InitBuffer();  // Reinitialize depth buffer
  67.  
  68.     // Walk the instance list
  69.     elem_id = 1;
  70.     pinst = pi;
  71.     while (pinst != NULL)
  72.     {
  73.       // Walk the surface list
  74.       psurf = pinst->GetSurfPtr();
  75.       while (psurf != NULL)
  76.       {
  77.         // Walk the patch list
  78.         ppatch = psurf->GetPatchPtr();
  79.         while (ppatch != NULL)
  80.         {
  81.           // Check for self patch
  82.           self = (BOOL)((ppatch == pp) ? TRUE : FALSE);
  83.  
  84.           // Determine patch visibility
  85.           hidden = clip.BackFaceCull(ppatch);
  86.  
  87.           // Walk the element list
  88.           pelem = ppatch->GetElementPtr();
  89.           while (pelem != NULL)
  90.           {
  91.             if (hidden == FALSE && self == FALSE)
  92.             {
  93.               // Clip element to face view volume
  94.               if (clip.Clip(pelem, out, elem_id) > 0)
  95.               {
  96.                 scan.Scan(out);     // Scan convert polygon
  97.               }
  98.             }
  99.             pelem = pelem->GetNext();
  100.             elem_id++;
  101.           }
  102.           ppatch = ppatch->GetNext();
  103.         }
  104.         psurf = psurf->GetNext();
  105.       }
  106.       pinst = pinst->GetNext();
  107.     }
  108.  
  109.     // Sum delta form factors
  110.     scan.SumDeltas(ff_array);
  111.   }
  112. }
  113.  
  114.